import React, { Component } from 'react'
import { FastAnswerApi } from "@/request/api"
import { withRouter } from "react-router";
import subject from "@/assets/images/home/subject.png";
import "./Fast.less"
import store from "@/store"


class Fast extends Component {

    state = {
        // 列表数组
        records: []
    }

    async componentDidMount() {
        let res = await FastAnswerApi();
        console.log(res);
        this.setState({ records: res.data.records })
    }
    render() {
        return (
            <div className="fast_page">
                <ul className="list">
                    {
                        this.state.records.map(item =>
                            <li key={item.id}>
                                <img src={subject} alt="" />
                                <section>
                                    <h3>{item.title}</h3>
                                </section>
                                <div className="btn" onClick={this.hdClick.bind(this)}>刷题</div>
                            </li>
                        )
                    }
                </ul>
            </div>
        )
    }

    hdClick() {
        let action = {
            type: "showAlert",
            value: {
                showAlert: true,
                alertType: "warning",
                alertContent: "该功能暂未开放"
            }
        }
        store.dispatch(action);
        setTimeout(() => {
            store.dispatch({
                type: "hideAlert"
            })
        }, 1500)
    }
}

export default withRouter(Fast)

